<?php
namespace app\walletyhbbadmin\controller;
use Think\Db;
// use Think\request;
require_once (APP_PATH .'api/FinanceApi.php');
class Discount extends AdminBase {


    public function index()
    {
        $res = DB::name('prom_order')->order('id desc')->paginate(10,false,['query'=>input()]);
		    	$page = $res->render();
		    	$this->assign('page',$page);//分页;
        $this->assign('list',$res);
        return $this->fetch('Discount/index');
    }
    //添加折扣
    public function Discount()
    {
        return $this->fetch('discount/adddiscount');
    }
    public function addDiscount()
    {
        $data['name'] = input('title');
        $data['money'] = input('gtmoney');
        $data['expression'] = input('preferential');
        $data['description'] = input('title');
        $data['is_close'] = input('status');
        if(empty($data['name']))
        {
            $this->error('请补全信息');
        }
        if(empty($data['money']))
        {
            $this->error('请补全信息');
        }
        if(empty($data['expression']))
        {
            $this->error('请补全信息');
        }
        $res = DB::name('prom_order')->insert($data);
        if($res)
        {
            $this->success('添加成功','Discount/index');
        }else{
            $this->error('添加失败');
        }
    }
//    删除折扣
    public function delDiscount()
    {
        $id = input('id');
        $res = DB::name('prom_order')->where('id',$id)->delete();
        $this->success('删除成功');
    }
//修改状态
	public function updateStatus(){
		//获取id
		$id=input('id');
		//获取的状态值
		$status['is_close']=input('is_close');
		$res=Db::name('prom_order')->where(array('id'=>$id))->update($status);
		if($res){
			$this->success('修改成功');
		}else{
			$this->error('系统繁忙,请稍后重试');
		}
	}
    //	修改信息
    public function upDiscount()
    {
        $id = input('id');
        $res = DB::name('prom_order')->where('id',$id)->find();
        $this->assign('info',$res);
        return $this->fetch('discount/updatediscount');
    }
    public function updateDiscount()
    {
        $id = input('id');
        $data['name'] = input('name');
        $data['money'] = input('money');
        $data['expression'] = input('expression');
        $data['description'] = input('title');
        $data['is_close'] = input('is_close');
        $arr = DB::name('prom_order')->where('id',$id)->update($data);
        if(empty($data['name']))
        {
            $this->error('请补全信息');
        }
        if(empty($data['expression']))
        {
            $this->error('请补全信息');
        }
        $res = DB::name('prom_order')->where('id',$id)->update($data);
            $this->success('修改成功','Discount/index');
    }

	//收益标准设置

    public function shouyi(){
        $shouyi = DB::name('config')->where('name',shouyi)->value('value');
        $this->assign('shouyi',$shouyi);
        return $this->fetch('discount/shouyi');
    }

    /*
     *修改配置项
     **/
    public function doupdate(){
        $data['value']=input('content');
        $res = DB::name('config')->where('name',shouyi)->update($data);
        if($res){
            $this->success('修改成功','/walletyhbbadmin/discount/shouyi');
        }else{
            $this->error('修改失败','/walletyhbbadmin/discount/shouyi');
        }
    }


}